package com.jinsilu.freight.ui.activity;

import android.util.TypedValue;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.fondesa.recyclerviewdivider.DividerDecoration;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.jinsilu.freight.R;
import com.jinsilu.freight.common.MyVBActivity;
import com.jinsilu.freight.databinding.ActivitySuggestionsListBinding;
import com.jinsilu.freight.helper.CommonHelper;
import com.jinsilu.freight.http.model.HttpListData;
import com.jinsilu.freight.http.request.GetSuggestionsListApi;
import com.jinsilu.freight.http.response.Suggestions;
import com.jinsilu.freight.ui.adapter.SuggestionsListAdapter;

import java.util.ArrayList;

/**
 * 投诉列表
 *
 * @author yangyang
 * @time 2021-01-19 9:55
 */
public class SuggestionsListActivity extends MyVBActivity<ActivitySuggestionsListBinding> {

    private SuggestionsListAdapter mAdapter;

    @Override
    protected void initView() {
        binding.recycler.setLayoutManager(new LinearLayoutManager(getContext()));
        DividerDecoration.builder(getContext())
                .asSpace().size(10, TypedValue.COMPLEX_UNIT_DIP)
                .showSideDividers()
                .showFirstDivider()
                .showLastDivider()
                .build()
                .addTo(binding.recycler);
        mAdapter = new SuggestionsListAdapter(new ArrayList<>());
        binding.recycler.setAdapter(mAdapter);
        mAdapter.setEmptyView(R.layout.layout_empty_view);
    }

    @Override
    protected void initData() {
        getSuggestionsList();
    }

    private void getSuggestionsList() {
        if (null == CommonHelper.getUserInfo()) return;
        // 获取投诉信息列表
        EasyHttp.get(this)
                .api(new GetSuggestionsListApi().setPhone(CommonHelper.getUserInfo().getPhone()))
                .request(new HttpCallback<HttpListData<Suggestions>>(this) {
                    @Override
                    public void onSucceed(HttpListData<Suggestions> data) {
                        mAdapter.setList(data.getData());
                    }
                });
    }
}
